const { autoTransaction } = require("../../util/db");
const { success, fail } = require('../../util/core');
const CommentService = require('../../services/web/commentService');

class CommentController {
    async getCommentsByPageController(ctx, next) {
        await autoTransaction(async (session) => {
            const setOpts = {
                populate: ['likeCount']
            }
            const res = await CommentService.getCommentsByPageService(ctx, { query: ctx.query, session, setOpts });
            success(ctx, res, `${ctx.query.page}页评论获取成功`)
        }).catch(err => {
            fail(ctx, '页面评论获取失败', 0, err.message)
        })
    }
}

module.exports = new CommentController();